package com.preguicoso.server.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.preguicoso.server.dao.ItemCardapioDAO;
import com.preguicoso.server.entities.ItemCardapio;

public class GetCardapioEstabelecimento extends HttpServlet{

		  /**
	 * 
	 */
	private static final long serialVersionUID = -4926295173748093247L;

		/**
	 * 
	 */

	@Override
	  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	      throws ServletException, IOException {
			PrintWriter out = resp.getWriter();
	    
		try{
			ItemCardapioDAO banco = new ItemCardapioDAO();
			ArrayList<ItemCardapio> lista = (ArrayList<ItemCardapio>) banco.listItensEstabelecimento(Long.parseLong(req.getParameter("id").trim()));
			String retorno = "[";
			for (ItemCardapio itemCardapio : lista) {
				retorno+=itemCardapio.toJSON();
				retorno+=",";			
			}
			retorno+="]";
			out.print(retorno);
		
		}catch (Exception e) {
			 out.println(" Ocorreu algum erro:" +e.getMessage());
		}
		
		
	  }
}
